import java.sql.*;

public class jdbcdemo7_PreparedStatement {

    public void PreparedStatement() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        /*本机MySQL并且端口3306可以简化书写
        String url = "jdbc:mysql://cc";
         */
        String url = "jdbc:mysql://192.168.2.131:3306/cc";
        String username = "root";
        String password = "abc123";
        Connection conn = DriverManager.getConnection(url,username,password);

        String name = "zhangsan";
        String pwd = "hjkssjkahf";
        String sql = "select * from tb_user where username = ? and password = ?";

       PreparedStatement pstmt = conn.prepareStatement(sql);

       pstmt.setString(1,name);
       pstmt.setString(2,pwd);


       ResultSet rs = pstmt.executeQuery();




        rs.close();
        pstmt.close();
        conn.close();
    }



}

